﻿using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Shapes;

namespace SLClient.CustomerControls
{
    public partial class ShowNxInfoControl : UserControl
    {
        public CheckBox BindCheckBox;
        private EventHandler _Clicked;
        private bool isBt = true;
        private ToolTip m_ToolTip = new ToolTip();

        public event EventHandler Clicked
        {
            add
            {
                EventHandler handler2;
                EventHandler clicked = this._Clicked;
                do
                {
                    handler2 = clicked;
                    EventHandler handler3 = (EventHandler)Delegate.Combine(handler2, value);
                    clicked = Interlocked.CompareExchange<EventHandler>(ref this._Clicked, handler3, handler2);
                }
                while (clicked != handler2);
            }
            remove
            {
                EventHandler handler2;
                EventHandler clicked = this._Clicked;
                do
                {
                    handler2 = clicked;
                    EventHandler handler3 = (EventHandler)Delegate.Remove(handler2, value);
                    clicked = Interlocked.CompareExchange<EventHandler>(ref this._Clicked, handler3, handler2);
                }
                while (clicked != handler2);
            }
        }

        public ShowNxInfoControl()
        {
            this.InitializeComponent();
            this.borderHead.MouseEnter += new MouseEventHandler(borderHead_MouseEnter);
            this.borderHead.MouseLeave += new MouseEventHandler(borderHead_MouseLeave);
            this.borderHead.MouseLeftButtonUp += new MouseButtonEventHandler(borderHead_MouseLeftButtonUp);
        }

        private void borderHead_MouseEnter(object sender, MouseEventArgs e)
        {
            if (!this.isBt)
            {
                VisualStateManager.GoToState(this, "MouseEntered", true);
            }
        }

        private void borderHead_MouseLeave(object sender, MouseEventArgs e)
        {
            if (!this.isBt)
            {
                VisualStateManager.GoToState(this, "Normal", true);
            }
        }

        private void borderHead_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!(this.isBt || (this._Clicked == null)))
            {
                this._Clicked(this, null);
            }
        }

        public void Init(int playid, string number, string fdStr, CheckBox checkBox)
        {
            string str;
            this.PlayTypeInfoId = playid;
            this.BindCheckBox = checkBox;
            this.Shownumber = Convert.ToInt32(number);
            this.lbNumber.Text=number;
            this.lbAmountLave.Text = str = fdStr;
            this.lbScale.Text = str;
            this.isBt = false;
            this.borderHead.Cursor = Cursors.Hand;
        }


        public void SetBt()
        {
            this.btBackAmountLave.Visibility = Visibility.Visible;
            this.btBackScale.Visibility = Visibility.Visible;
        }

        public void SetFd(string fdStr)
        {
            string str;
            this.lbAmountLave.Text = str = fdStr;
            this.lbScale.Text = str;
        }

        public void SetScale(decimal scale, decimal amountlave)
        {
            this.lbScale.Text = scale.ToString("F2");
            this.lbAmountLave.Text=amountlave.ToString("F2");
            ToolTipService.SetToolTip(this.borderHead, this.m_ToolTip);
        }

        public int PlayTypeInfoId { get; set; }

        public int Shownumber { get; set; }
    }
}
